#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //子进程
        printf("子进程开始运行，pid：%d\n",getpid());
        sleep(3);
        //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
        execlp("ls", "ls", "-l", "-a", NULL);
        exit(1);

    }
    else 
    {
        //父进程
        printf("父进程开始运行,pid:%d\n",getpid());
        int status = 0;
        pid_t id = waitpid(-1, &status, 0);
        if(id > 0)
        {
            printf("wait success, exit code: %d\n", WEXITSTATUS(status));

        }
    }
    return 0;
}
